package com.smartpro.mis.modular.system.dao;

import com.smartpro.mis.modular.business.neo4jEntity.BuyNotPayRelationship;
import com.smartpro.mis.modular.business.neo4jEntity.N4jProduct;
import com.smartpro.mis.modular.business.neo4jEntity.N4jUser;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.Collection;

/**
 * @author Mengiy
 */
@RepositoryRestResource(collectionResourceRel = "buyNotPayRelationship", path = "buyNotPayRelationship")
public interface BuyNotPayRelationRepository extends Neo4jRepository<BuyNotPayRelationship, Long> {

	BuyNotPayRelationship findByN4jUser(@Param("n4jUser") N4jUser n4jUser);

	@Query("MATCH (m:BuyNotPayRelationship) where n.n4jUser={n4jUser} and n.n4jProduct={n4jProduct} delete m")
	void deleteBuyNotPayRelationship(@Param("n4jUser") N4jUser n4jUser,@Param("n4jProduct") N4jProduct n4jProduct);


	@Query("MATCH (m:BuyNotPayRelationship) where n.n4jUser={n4jUser} and n.n4jProduct={n4jProduct} RETURN m LIMIT 1")
	BuyNotPayRelationship findByN4jUserAndProduct(@Param("n4jUser") N4jUser n4jUser,@Param("n4jProduct") N4jProduct n4jProduct);


    @Query("MATCH (m:BuyNotPayRelationship) RETURN m.n4jUser LIMIT {limit}")
	Collection<N4jUser> graph(@Param("limit") int limit);
}